﻿using System;
using System.Text.RegularExpressions;

class Ex8ExtractUrlElements
{
    static void Main()
    {
        string text = "Here are : some : @ ! url with http or http://www.data.bg/ without and http://www.mtel.bg/sms/send_sms.php? some : abv.bg is this a url? or something i send sms https://www.mtel.bg/sms/send_sms.php " +
            "here is a valid url http://regexlib.com/DisplayPat/terns.aspx?cattabindex=1&categoryId=2 " +
            "https://www.codeplex.com "
            + "http://www.google.bg/ig?hl=bg&source=iglk ";
        string pattern = @"((?<protocol>https?)://)?(www\.)?(?<server>([\w\&\?=-]+\.)+[A-z]{2,4})(?<resource>(\/([\w\&\?=-]+)(\.[\w\&\?=-]+)*)*)?";
        Regex rg = new Regex(pattern);
        foreach (Match match in rg.Matches(text))
        {
            Console.WriteLine("match:" + match);
            Group protocol = match.Groups["protocol"];
            Group server = match.Groups["server"];
            Group resource = match.Groups["resource"];
            Console.WriteLine("protocol:" + protocol);
            Console.WriteLine("server:" + server);
            Console.WriteLine("resource:" + resource);
            Console.WriteLine(new string('-', 50));
        }
    }
}

